package com.tqyan.model;

import lombok.Data;

import java.io.Serializable;

/**
 * @description 结果
 * <p> <功能详细描述> </p>
 *
 * @author 陈晨
 * @date 2023/4/12 01:17
 */
@Data
public class Result<T> implements Serializable {
    private static final long serialVersionUID = 6340215166237286752L;

    private boolean result;
    private String code;
    private String message;
    private T data;

    private Result() {}

    private Result(boolean result, String code, String message, T data) {
        this.result = result;
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static <T> Result<T> success(T data) {
        Result<T> result = new Result<>();
        result.setResult(true);
        result.setCode("200");
        result.setMessage("成功");
        result.setData(data);
        return result;
    }

    public static <T> Result<T> success() {
        return success(null);
    }

    public static <T> Result<T> fail(String code, String errorMessage) {
        Result<T> result = new Result<>();
        result.setResult(false);
        result.setCode(code);
        result.setMessage(errorMessage);
        return result;
    }

    public static <T> Result<T> fail(String errorMessage) {
        return fail("500", errorMessage);
    }

}


